package com.geeksaga.dao.ibatis.mysql;

import java.util.List;

import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import com.geeksaga.common.util.DateConvertor;
import com.geeksaga.dao.ProjectDao;
import com.geeksaga.dao.ibatis.BaseIBatisDao;
import com.geeksaga.domain.Project;

/**
 * @author newbie
 * @since 0.1
 */
@Repository
public class ProjectDaoImpl extends BaseIBatisDao implements ProjectDao {

    /* (non-Javadoc)
     * @see com.geeksaga.dao.ProjectDao#add(com.geeksaga.domain.Project)
     */
    public Project add(Project project) throws DataAccessException {
        project.setRegistDate(DateConvertor.getDateFormat());
        project.setRegistTime(DateConvertor.getTimeFormat());
        project.setModifyDate(DateConvertor.getDateFormat());
        project.setModifyTime(DateConvertor.getTimeFormat());
        
        return (Project) getSqlMapClientTemplate().insert("PROJECT.add", project);
    }

    /* (non-Javadoc)
     * @see com.geeksaga.dao.ProjectDao#list()
     */
    @SuppressWarnings("unchecked")
    public List<Project> list() throws DataAccessException {
        return (List<Project>) getSqlMapClientTemplate().queryForList("PROJECT.list");
    }
}